﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.Common;
using System.Xml;
using System.Data;

namespace WoWGRA
{
    /// <summary>
    /// Interaction logic for BossWindow.xaml
    /// </summary>
    public partial class BossWindow : Window
    {
        public TabItem tabinfo;

        public BossWindow()
        {
            InitializeComponent();
            BossLabel2.Content = MainWindow.Bosslabel;
            fillitin2();
            loadraid();
           // FillListBoxs();
            
        }
        public void loadraid()
        {

            DataSet GuildRoster = new DataSet("GuildRoster");
            GuildRoster.ReadXml("GuildRoster.xml");
            string member = string.Empty;
            foreach (DataRow r in GuildRoster.Tables[1].Rows)
            {
                if (r["MainRaider"].ToString() == "1")
                {
                    member = r["Members"] + " , " + r["Role"];
                    listBox5.Items.Add(member);
                }
            }
        }
        public void fillitin2()
        {
            int x = 0;
            
            TabControl tabControl1 = tabItem1.Parent as TabControl;
            
            TabItem tabinfo = tabItem1.Content as TabItem;
            //Grid tabinfo = this.GridMain.Children as Grid;
            string tabname = string.Empty;
            string bossname = string.Empty;
            DataSet RaidBuildRecommendation = new DataSet("RaidBuildRecommendation");
            RaidBuildRecommendation.ReadXml("RaidBuildRecommendation.xml");
            string reccommended = string.Empty;
            int row = 0;
            string instance = string.Empty;
            while (x < MainWindow.strArray.Length)
            {
               
                TabItem Item1 = new TabItem();
                if (x == 0)
                {
                    tabItem1.Header = MainWindow.strArray[x];
                    bossname = tabItem1.Header.ToString();
                    if (MainWindow.Hcheck == true)
                    {
                        instance = MainWindow.instance + "25";
                    }
                    row = FindRow(instance, tabItem1.Header.ToString(), RaidBuildRecommendation);
                    if (checkBox1.IsChecked == false)
                    {
                        reccomendedtanks.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Tanks"].ToString();
                        ReccomendedHealers.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Healers"].ToString();
                        Reccomendedrange.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Ranged"].ToString();
                        ReccomendedMelee.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Melee"].ToString();
                    }
                    else
                    {
                        reccomendedtanks.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Htanks"].ToString();
                        ReccomendedHealers.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Hhealers"].ToString();
                        Reccomendedrange.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Hranged"].ToString();
                        ReccomendedMelee.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Hmelee"].ToString();
                    }
                }
                else
                {
                    Item1.Header = MainWindow.strArray[x];
                    tabControl1.Items.Add(Item1);
                    Item1.Content = tabinfo;
                }
              
                x++;
            }
            

        } 
        private void closeTabItem(TabItem item)    
        {         
            if (item != null)        
            {             
                // find the parent tab control             
                TabControl tabControl = item.Parent as TabControl;             
                if (tabControl != null)                 
                    tabControl.Items.Remove(item); 
                // remove tabItem         
            }     
        }
        public int FindRow(string instance, string boss, DataSet data)
        {
            int rowid = 0;
            int count = 0;
            foreach (DataRow r in data.Tables[1].Rows)
            {
                if (r["Instance"].ToString() == instance)
                {
                    if (r["Boss"].ToString() == boss)
                    {
                        rowid = count;
                    }
                }
                count++;
            }
            return rowid;
        }

        private void checkBox1_Checked(object sender, RoutedEventArgs e)
        {
            DataSet RaidBuildRecommendation = new DataSet("RaidBuildRecommendation");
            RaidBuildRecommendation.ReadXml("RaidBuildRecommendation.xml");
            string instance = "";
             string bossname = tabItem1.Header.ToString();
            if (MainWindow.Hcheck == true)
            {
                instance = MainWindow.instance + "25";
            }
            int row = FindRow(instance, tabItem1.Header.ToString(), RaidBuildRecommendation);
            if (checkBox1.IsChecked == false)
            {
                reccomendedtanks.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Tanks"].ToString();
                ReccomendedHealers.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Healers"].ToString();
                Reccomendedrange.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Ranged"].ToString();
                ReccomendedMelee.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Melee"].ToString();
            }
            else
            {
                reccomendedtanks.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Htanks"].ToString();
                ReccomendedHealers.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Hhealers"].ToString();
                Reccomendedrange.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Hranged"].ToString();
                ReccomendedMelee.Text = RaidBuildRecommendation.Tables["RaidRecommendation"].Rows[row]["Hmelee"].ToString();
            }
            
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            listBox1.Items.Add(listBox5.SelectedItem);
            listBox5.Items.Remove(listBox5.SelectedItem);
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            listBox2.Items.Add(listBox5.SelectedItem);
            listBox5.Items.Remove(listBox5.SelectedItem);
        }

        private void button5_Click(object sender, RoutedEventArgs e)
        {
            listBox3.Items.Add(listBox5.SelectedItem);
            listBox5.Items.Remove(listBox5.SelectedItem);
        }

        private void button6_Click(object sender, RoutedEventArgs e)
        {
            listBox4.Items.Add(listBox5.SelectedItem);
            listBox5.Items.Remove(listBox5.SelectedItem);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            listBox5.Items.Add(listBox1.SelectedItem);
            listBox5.Items.Add(listBox2.SelectedItem);
            listBox5.Items.Add(listBox3.SelectedItem);
            listBox5.Items.Add(listBox4.SelectedItem);
            listBox1.Items.Remove(listBox1.SelectedItem);
            listBox2.Items.Remove(listBox2.SelectedItem);
            listBox3.Items.Remove(listBox3.SelectedItem);
            listBox4.Items.Remove(listBox4.SelectedItem);
        }
        

    }
   
}
